//
//  AppDelegate.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/4/27.
//

import UIKit
import QMUIKit
import CYLTabBarController
import MJRefresh
import ShareSDK
import ShareSDKUI
import EachNavigationBar

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    
        
    var window: UIWindow?
    
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
     
      //  MJRefreshConfig.default.languageCode = "zh"
        QMUIConsole.sharedInstance().canShow = true
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.backgroundColor = UIColor.white
        IAPHelper.shared.config()
        
        
        let tokenInfo = UserDefaults.standard.string(forKey: "LoginToken")
        
        print("\(String(describing: tokenInfo))")
        
        if tokenInfo == nil  {
            Login()
        }else {
            tabbarInfo()
        }
        self.window?.makeKeyAndVisible()
        
        LQShareSDK.registApp()
        
        return true
    }
        
    
    func Login() -> Void {
        //登录
        let loginVc = MCLoginVc.init()
        let loginNavigationVc = MCNavigationVc(rootViewController: loginVc)
        
        self.window?.rootViewController = loginNavigationVc
    }
    
    
    func tabbarInfo() -> Void {
        let titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3.5)
        let inLineLayoutAppearance = UITabBarItemAppearance.init()
        inLineLayoutAppearance.normal.titlePositionAdjustment = titlePositionAdjustment

        inLineLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
        inLineLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]

        let standardAppearance = UITabBarAppearance.init()
        standardAppearance.backgroundColor = UIColor.qmui_color(withHexString: "#10151C")
        standardAppearance.stackedLayoutAppearance = inLineLayoutAppearance
         

//        let  tabBarVc = MCTabBarVc.init(viewControllers: self.tabBarToController(), tabBarItemsAttributes: self.tabBarItemsAttributeForController())
//        tabBarVc.hideTabBarShadowImageView()

        
        let tabBarVc = MCTabBarContro()
        tabBarVc.tabBar.standardAppearance = standardAppearance
        
        UITabBar.appearance().backgroundColor = UIColor.qmui_color(withHexString: "#10151C")
        
        tabBarVc.tabBar.tintColor = UIColor.qmui_color(withHexString: "#35DE94")
        self.window?.rootViewController = tabBarVc
        
    }
    
    
    
    
    func tabBarToController() -> [UINavigationController] {
        //计划
        let planVc = MCPlanVc.init()
        let planNavigation = MCNavigationVc(rootViewController: planVc)
        planNavigation.isNavigationBarHidden = true
        
//        planNavigation.navigation.configuration.isEnabled = true
//        planNavigation.navigation.configuration.barTintColor = UIColor.white
//        planNavigation.navigation.configuration.tintColor = UIColor.black
//        
//        let shadow = Shadow(
//            color: UIColor.white.cgColor,
//            opacity: 0.5,
//            offset: CGSize(width: 0, height: 1)
//        )
//        planNavigation.navigation.configuration.shadow = shadow
        
        //动作
        let actionVc = MCActionVc.init()
        let actionNavigationVc = MCNavigationVc.init(rootViewController: actionVc)
        actionNavigationVc.isNavigationBarHidden = true
        
        //饮食
        let dietVc = MCDietVc.init()
        let dietNavigaitonVc = MCNavigationVc.init(rootViewController: dietVc)
        dietNavigaitonVc.isNavigationBarHidden = true
        
        //个人中心
        let mineVc = MCMineVc.init()
        let mineNavigationVc = MCNavigationVc(rootViewController: mineVc)
        mineNavigationVc.isNavigationBarHidden = true
        
        return [planNavigation,actionNavigationVc,dietNavigaitonVc,mineNavigationVc]
        
    }
    
    
    ///tabbar 设置
    func tabBarItemsAttributeForController() -> [[String:String]] {
        let tabBarItemOne = [CYLTabBarItemTitle:"计划",
                             CYLTabBarItemImage:"plan_unselect_tabbar_image",
                     CYLTabBarItemSelectedImage:"plan_select_tabbar_image"]
        
        let tabBarItemTwo = [CYLTabBarItemTitle:"动作",
                             CYLTabBarItemImage:"action_tabbar_unselect_image",
                             CYLTabBarItemSelectedImage:"action_tabbar_select_image"]
        
        let tabBarItemThree = [CYLTabBarItemTitle:"饮食",
                               CYLTabBarItemImage:"yinshi_unselect_tabbar_image",
                               CYLTabBarItemSelectedImage:"yinshi_select_tabbar_image"]
        
        let tabBarItemFour = [CYLTabBarItemTitle:"我的",
                              CYLTabBarItemImage:"mine_tabbar_unselect_image",
                              CYLTabBarItemSelectedImage:"mine_tabbar_select_image"]
        let tabBarItemsAttributes = [tabBarItemOne,tabBarItemTwo,tabBarItemThree,tabBarItemFour]
        return tabBarItemsAttributes
    }
    
    
}

